/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbquestion_client.form;

import bllobjects.Account;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JFrame;
import model.ClientModel;

/**
 *
 * @author Mrkupi
 */
public class userInfo extends javax.swing.JFrame
{
    /**
     * Creates new form userInfo
     */
    public userInfo() {
        initComponents();
        
        onLoadInfo();
    }

    private void createFriendList()
    {
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e){
                e.getWindow().setVisible(false);
            }
        });
        
        scrollPaneFriendlist = new javax.swing.JScrollPane();
        friendList  =   new javax.swing.JList(ClientModel.getInstance().getFriendList()){
             @Override
             public String getToolTipText(MouseEvent e)
             {
                 int index = locationToIndex(e.getPoint());
                 if (-1 < index) 
                 {
                     return ((Account) this.getModel().getElementAt(index)).getDescription();
                 } 
                 else 
                 {
                     return null;
                 }
             }
        };
        scrollPaneFriendlist.setViewportView(friendList);
        friendList.setLocation( 170, 190);
        friendList.setVisible( true );
        friendList.setSize(400, 250);
        friendList.setBorder(BorderFactory.createLineBorder(Color.black));
        friendList.addMouseListener( new MouseAdapter(){
            @Override
            public void mousePressed( MouseEvent e )
            {
            }
            
            @Override
            public void mouseClicked( MouseEvent e )
            {
                if( e.getClickCount() == 2 )
                {
                    Account selectedFriend = (Account) friendList.getSelectedValue();
                    if (selectedFriend != null && !selectedFriend.getUserID().equals(
                            ClientModel.getInstance().getAccount().getUserID()))
                    {
                        ClientModel.getInstance().getForms().showChatForm(selectedFriend, ClientForms.CHATFORM_PRIVATE);
                    }
                }
            }
        } );
        this.add( friendList );
    }
    
    private void onLoadInfo()
    {
        createFriendList();
        this.lblNickName.setText( ClientModel.getInstance().getAccount().getUserName() );
        this.lblExp.setText( String.valueOf( ClientModel.getInstance().getAccount().getExp() ) );
        this.lblLevel.setText( String.valueOf( ClientModel.getInstance().getAccount().getLevel() ) );
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnInfo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblLevel = new javax.swing.JLabel();
        lblExp = new javax.swing.JLabel();
        lblNickName = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        btChangePassword = new javax.swing.JButton();
        btDeleteAccount = new javax.swing.JButton();
        lblUserName = new javax.swing.JLabel();
        btnAvatar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("USER INFO");

        pnInfo.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Level");

        jLabel2.setText("Exp");

        jLabel4.setText("Nick name");

        lblLevel.setText("jLabel5");

        lblExp.setText("jLabel6");

        lblNickName.setText("jLabel8");

        javax.swing.GroupLayout pnInfoLayout = new javax.swing.GroupLayout(pnInfo);
        pnInfo.setLayout(pnInfoLayout);
        pnInfoLayout.setHorizontalGroup(
            pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLevel)
                    .addComponent(lblExp)
                    .addComponent(lblNickName))
                .addContainerGap(269, Short.MAX_VALUE))
        );
        pnInfoLayout.setVerticalGroup(
            pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblLevel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblExp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblNickName))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Friend List");
        jLabel9.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btChangePassword.setText("Change Password");
        btChangePassword.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                onChangePassword_click(evt);
            }
        });

        btDeleteAccount.setText("Delete Account");
        btDeleteAccount.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                onDeleteAccount_clicked(evt);
            }
        });

        lblUserName.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblUserName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblUserName.setText("USER INFO");

        btnAvatar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/popo_emotions_full_version boss copy.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btChangePassword, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                    .addComponent(btDeleteAccount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAvatar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(289, 289, 289)
                .addComponent(lblUserName)
                .addContainerGap(193, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblUserName)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAvatar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btChangePassword)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btDeleteAccount)
                .addGap(0, 203, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    
    private void onChangePassword_click(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onChangePassword_click
        JDialog changePasswordDialog = new JDialog(this, "Change password", true);
        ChangePassword chgPassPanel = new ChangePassword(changePasswordDialog);
        changePasswordDialog.getContentPane().add(chgPassPanel);
        changePasswordDialog.setSize(400, 200);
        changePasswordDialog.setResizable(false);
        changePasswordDialog.setLocation(new Point(400, 400));
        changePasswordDialog.setVisible(true);
    }//GEN-LAST:event_onChangePassword_click

    private void onDeleteAccount_clicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_onDeleteAccount_clicked
        // TODO add your handling code here:
    }//GEN-LAST:event_onDeleteAccount_clicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btChangePassword;
    private javax.swing.JButton btDeleteAccount;
    private javax.swing.JButton btnAvatar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel lblExp;
    private javax.swing.JLabel lblLevel;
    private javax.swing.JLabel lblNickName;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JPanel pnInfo;
    // End of variables declaration//GEN-END:variables
    private javax.swing.JList friendList;
    private javax.swing.JScrollPane scrollPaneFriendlist;
}
